class Solution {
    // 移动零
    public void moveZeroes(int[] nums) {
        // [0, left) 非零
        // [left, right) 全零
        // [right, len] 未扫描
        int left = 0;
        int right = 0;
        int len = nums.length;
        while(left < len && nums[left] != 0) {
            left++;
        }
        right = left;
        while(right < len) {
            if(nums[right] != 0) {
                nums[left] = nums[right];
                nums[right] = 0; // 当 left = right 时会修改原有的值
                left++;
            }
            right++;
        }
    }
    public void moveZeroes2(int[] nums) {
        // [0, left] 非零
        // (left, right] 全零
        // (right, len] 未扫描
        int left = -1;
        int right = 0;
        int len = nums.length;
        // while(left < len && nums[left] != 0) {
        //     left++;
        // }
        // right = left;
        while(right < len) {
            if(nums[right] != 0) {
                left++;
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
            }
            right++;
        }
    }
    public void moveZeroes3(int[] nums) {
        // [0, left) 非零
        // [left, right) 全零
        // [right, len] 未扫描
        int left = 0;
        int right = 0;
        int len = nums.length;
        while(right < len) {
            if(nums[right] != 0) {
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
                left++;
            }
            right++;
        }
    }
}